#include "StdAfx.h"
#include "MySprite.h"

CMySprite::CMySprite(LPWSTR path) {
	bmSprite = new Bitmap(path);
	frPos = 0;
	px = 0;
	py = 0;
}
CMySprite::CMySprite(void)
{
	frPos = 0;
	px = 0;
	py = 0;
}

CMySprite::~CMySprite(void)
{

}

void CMySprite::GetRect(int numFr, int realFr) {
	rectX			= bmSprite->GetWidth();
	rectY			= bmSprite->GetHeight();

	if (numFr != -1) 
		numFrame	= numFr ;
	else
		numFrame	= rectX / rectY;

	if (realFr!=-1)
		aniFrame	= realFr;
	else
		aniFrame	= numFrame;

	rectX			= rectX / numFrame;	
	
	
}
void CMySprite::PrevFrame()
{
	frPos--;
	int staticFr = numFrame - aniFrame -1;
	if (frPos <= staticFr)
		frPos = numFrame-1;
}
void CMySprite::NextFrame()
{
	frPos++;
	if (frPos > aniFrame-1 )
		frPos = 0;
}

void CMySprite::RenderPosition(int x,int y) {
	if (x != -1){
		currX = x;
		px = x;
	}
	if (y != -1) {
		py = y;
		currY = y;
	}
}

void CMySprite::RenderAnimation(HDC *pDC) {
	Graphics graphic(*pDC);
	graphic.DrawImage(bmSprite,px,py,frPos*rectX,0,rectX,rectY,UnitPixel);
}

void CMySprite::Render(HDC *pDC,int frPosition) {
	Graphics graphic(*pDC);
	graphic.DrawImage(bmSprite,px,py,frPosition*rectX,0,rectX,rectY,UnitPixel);
}
void CMySprite::Render(Bitmap* bitmap,int frPosition) {
	Graphics graphic(bitmap);
	if (frPosition == -1)
		graphic.DrawImage(bmSprite,px,py,frPos*rectX,0,rectX,rectY,UnitPixel);
	else
		graphic.DrawImage(bmSprite,px,py,frPosition*rectX,0,rectX,rectY,UnitPixel);
	
}
void CMySprite::DrawBitmap(HDC *pDC) {
	Graphics graphic(*pDC);
	graphic.DrawImage(bmSprite,
						px,py,
						frPos*rectX,0,
						2000,1000,
						UnitPixel
					 );
}

